import {Component, OnInit, TemplateRef, Input, Output, EventEmitter} from '@angular/core';
import {NgSwitch} from '@angular/common'

@Component({
    selector: 'app-message',
    templateUrl: 'message.component.html',
    styleUrls: ['message.component.css']
})
export class MessageComponent implements OnInit {
    //告诉我我自己是谁，好分出左右显示
    @Input() loginInfo: any;
    @Input() messages: any;
    //给他定义一个 输出事件： onMessageClicked
    @Output() onMessageClicked = new EventEmitter<any>();

    constructor() {
    };

    ngOnInit() {

    };

    //点击某条信息事件，待处理
    msgSelected(message: any) {
        console.log('msgSelected ---- ');
        console.dir(message);
        this.onMessageClicked.emit(message);
    }

    //自动滚动到底，最下面一行保持可见
    scrollLastRowIntoView() {
        //如果获取 ul 的 tag可能好一些
        var items = document.getElementById("messageList");

        if (!items) return;
        else {
            items.lastElementChild.scrollIntoView(true);
        }
    };

    //监听节点增加监控
    onDOMNodeInserted() {
        setTimeout(()=>{
            this.scrollLastRowIntoView();
        },300);
    }
}
